/**
 * EdgeAndWeight.java
 * This is a storage unit which stores a pair of vertices and its 
 * corresponding weight.  This unit is stored inside of the list 
 * containing all of the edges in a given graph, to be sorted.
 */
package queue;

public class EdgeAndWeight implements Comparable {
	Object origin, dest;
	int weight;

	/**
	 * Constructor constructs an EdgeAndWeight object, which stores as 
	 * fields the origin, destination, and weight of a particular edge.  
	 * It is designed to allow the sorting algorithm to couple the edge 
	 * information with the weight used in the sort.
	 * @param o1 is the origin of the edge
	 * @param o2 is the destination of the edge
	 * @param weight is the weight of the edge
	 */
	public EdgeAndWeight(Object o1, Object o2, int weight) {
		origin = o1;
		dest = o2;
		this.weight = weight;
	}

	/**
	 * origin() is a selector for the EdgeAndWeight's origin, designed for 
	 * outside classes to have access to (but not change) the data.
	 * @return the origin field of the edge
	 */
	public Object origin() {
		return origin;
	}

	/**
	 * dest() is a selector for the EdgeAndWeight's dest field, 
	 * designed for outside classes to have access to (but not change) the 
	 * data.
	 * @return the dest field of the edge
	 */
	public Object dest() {
		return dest;
	}

	/**
	 * weight() is a selector for the EdgeAndWeight's weight, designed for 
	 * outside classes to have access to (but not change) the data.
	 * @return weight, the weight of an edge.
	 */
	public int weight() {
		return weight;
	}

	/**
	 * compareTo() implements Comparable by forcing comparisons by weight.
	 */
	public int compareTo(Object o) {
		return this.weight - ((EdgeAndWeight)o).weight;
	}

	/**
	 * toString() returns a string representation of the EdgeAndWeight.
	 */
	public String toString() {
		return "[ (" + origin + ", " + dest + ") Weight: " + weight + " ]";
	}
}
